import easygui as g
import sys
import random
while 1:
    secret = random.randint (1,10)
    g.msgbox('游戏开始','数字小游戏')
    temp=g.enterbox('请输入数字','数字小游戏')
    try:
        while not temp.isdigit():
            temp = g.enterbox('请输入数字\n')
    except AttributeError:
        break
    guess = int(temp)
    i=0
    while (guess != secret) or (i<3):
        i+=1
        if guess == secret:
            g.msgbox ('你猜对了','数字小游戏')
            break
        else:
            if guess < secret:
                g.msgbox('小了','数字小游戏')

            else:
                g.msgbox('大了','数字小游戏')
            if i < 3:
                temp = g.enterbox('请输入数字','数字小游戏')
                guess = int(temp)
            else:
                g.msgbox('你猜错了\n次数用完','数字小游戏')
                break
    g.msgbox ('游戏结束','数字小游戏')
    if g.ccbox('是否继续','请选择'):
        pass
    else :
        sys.exit(0)
    
